﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyRead.API.Appicant.Command;
using B.S.DataBase.MyRead.API.Appicant.Command.Approval;
using B.S.DataBase.MyRead.API.Appicant.Command.Menus;
using B.S.DataBase.MyRead.API.Appicant.Command.RoleMenus;
using B.S.DataBase.MyRead.API.DTOs;
using B.S.DataBase.MyWrite.API.Appicant.Command.Users;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.DataBase.MyRead.API.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MessageController : ControllerBase
    {
        private readonly IMediator mediator;

        public MessageController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<APIResult<List<LoginDto>>> Login([FromQuery] LoginCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }
        /// <summary>
        /// 查询用户列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<User>>> GetUser([FromQuery] GetUserCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 用户名称唯一
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<object>> OneUserName([FromQuery] OnenessUserNameCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取反填数据
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<APIResult<List<User>>> FanTianUser([FromQuery] FanTianUserCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 查询角色列表
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<APIPaging<List<Role>>> GetRole([FromQuery] GetRoleCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 反填角色列表
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public async Task<APIResult<List<Role>>> FanTianRole([FromQuery] FanTianRoleCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 查询部门用户
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<User>>> GetUserNameByDepId([FromQuery] GetDepCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 根据角色编号获取用户名称
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<UserRoleDTO>>> GetUserNameByRoleId([FromQuery] GetUserRoleCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取整个列表
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<UserRoleDTO>>> GetAll([FromQuery] GetRolaNameCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 获取用户角色部门数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet("UserRoledep")]
        public Task<APIResult<List<UserRoledepDto>>> UserRoledep([FromQuery] UserRoledepCommends request)
        {
            return mediator.Send(request);
        }


        #region 菜单

        /// <summary>
        /// 查询菜单--自查
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet("MenuQuery")]
        public Task<APIResult<List<MenuDtos>>> Handle([FromQuery]MenuQueryCommends request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 根据菜单ID查询菜单信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpGet("FanTianUpData")]
        public async Task<APIResult<List<Menu>>> FanTianUpData([FromQuery]FanTianUpDataMenuCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }


        /// <summary>
        /// 查询子菜单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet("ChildMenus")]
        public Task<APIResult<object>> Handle([FromQuery]GetChildMenusCommends request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }
        #endregion


        #region 角色菜单
        /// <summary>
        /// 获取菜单树状图
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet("ChildrenMenus")]
        public Task<APIResult<List<ChildrenMenusDto>>> GetChildrenMenus([FromQuery]GetMenuCommends request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 根据角色获取菜单信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet("GetRoleMenu")]
        public Task<APIResult<List<RoleMenu>>> GetRoleMenu([FromQuery]GetRoleMenuCommends request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 获取角色————角色分配权限
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpGet("GetRole")]
        public Task<APIResult<List<getRolesDto>>> GetRole([FromQuery]GetRoleCommends request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 查询菜单名称
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet("GetMenuName")]
        public async Task<APIResult<List<Menu>>> GetMenuName([FromQuery]GetMenuNameCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }
        #endregion


        #region 审批

        /// <summary>
        /// 根据部门ID获取部门领导
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet("GetDepHeads")]
        public Task<APIResult<List<User>>> GetDepHeads([FromQuery]GetDepHeadsCommends request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 显示申请表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// 
        [HttpGet("GetLeaveApplication")]

        public Task<APIPaging<List<LeaveApplicationsHeadsDtos>>> GetLeaveApplication([FromQuery]GetLeaveApplicationCommends request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }


        /// <summary>
        /// 获取请假申请数据--修改1
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet]
        public async Task<APIResult<List<LeaveApplications>>> FanTianLeaveApplication([FromQuery]FanTianLeaveApplicationCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 获取记录表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet]
        public async Task<APIResult<List<Record>>> FanTianRecord([FromQuery]FanTianRecordCommends request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 查询记录--表格形式
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        /// 
        [HttpGet]
        public Task<APIResult<List<Record>>> RecordQuery([FromQuery]RecordQueryCommends request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }
        #endregion
    }
}
